﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BDS3M.Controls
{
    public partial class BoxInBoxMail : System.Web.UI.UserControl 
    {
        public static int sizepage = 1;
        public static int cur;

        protected void Page_Load(object sender, EventArgs e)
        {            
            if (!Page.IsPostBack) 
            {
                if (Request.QueryString["currentPage"] != null)
                {
                    cur = Convert.ToInt32(Request.QueryString["currentPage"].ToString());
                    string iduser = Session["Employee_ID"].ToString();                    
                    rpt_listmail.DataSource = DAL.DCollector.DBCollector.Instance.Paging7Param("paging7Param", "tbl_Message", "Message_Date", cur.ToString(), sizepage.ToString(), "desc", "Message_To", iduser.ToString(), true);
                    rpt_listmail.DataBind();
                }
                else
                {
                    cur = 1;
                    string iduser = Session["Employee_ID"].ToString();                   
                    rpt_listmail.DataSource = DAL.DCollector.DBCollector.Instance.Paging7Param("paging7Param", "tbl_Message", "Message_Date", "1", sizepage.ToString(), "desc", "Message_To", iduser.ToString(), true);
                    rpt_listmail.DataBind();
                }
              
            }
        }


        public string getUserfromID(string id)
        {
            return DAL.DCollector.DBCollector.Instance.StoredSelectAllTableWhereID("tbl_Employee", "Employee_ID", id).Rows[0]["Employee_User"].ToString();
        }

        protected void rpt_listmail_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
        
                if (e.CommandName == "delete")
                {
                    // Xoa
                    int id = Convert.ToInt32(e.CommandArgument.ToString());
                    DAL.DCollector.DBCollector.Instance.StoredProcedureDeleteByRows("tbl_Message", "Message_ID", id.ToString());
                    Response.Redirect("/hopthuden");
                }
  
        }
    }

}